$(document).ready(
	function() {
		$('#ext_media_save_button').bind('click', function() {
			var oParams = {};
			
			oParams.iExtMediaId = $('#ext_media_id').val();
			oParams.sExtMediaTitle = $('#ext_media_title').val();
			oParams.sExtMediaContent = $('#ext_media_content').val();
			
			if (oParams.sExtMediaTitle === '') {
				$.prompt('Please enter a title/name for this external media');
				return;
			}
			
			if (oParams.sExtMediaContent === '') {
				$.prompt('Please enter some HTML or Javascript for this external media');
				return;
			}
			
			$.post('/admin/ext_media_conf/ajax/save_ext_media', oParams, function(data) {
				if (data.iExtMediaId) {
					$.prompt('External media has been saved', {
						callback : function() {
							location.href = '/admin/ext_media_conf';
						}
					});
				}
			}, 'json');
		});
	}
);